Skip to content

precompute contraction GL*A and A*GR in JordanMPO_AC_Hamiltonian and JordanMPO_AC2_Hamiltonian - #330

Closed
AFeuerpfeil wants to merge 21 commits into
QuantumKitHub:mainfrom
AFeuerpfeil:main
Closed

precompute contraction GL*A and A*GR in JordanMPO_AC_Hamiltonian and JordanMPO_AC2_Hamiltonian#330
AFeuerpfeil wants to merge 21 commits into
QuantumKitHub:mainfrom
AFeuerpfeil:main

Conversation

@AFeuerpfeil

Copy link
Copy Markdown
Contributor

This PR changes the way JordanMPO_AC2_Hamiltonian and JordanMPO_AC_Hamiltonian deal with the A-block of the MPO:
To reduce contraction const in the application to an MPS MPSTensor, we contract GL*A and A*GR in the constructor for the 2-site derivative and GL*A for the 1-site derivative (absorbing A into the left environment is purely conventional. If the mpo leg of the left and right environments have different sizes, one of the 2 conventions could be superior to the other.)

@github-actions

github-actions Bot commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic main) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/algorithms/derivatives/mpo_derivatives.jl b/src/algorithms/derivatives/mpo_derivatives.jl
index 02ec00b..587a45f 100644
--- a/src/algorithms/derivatives/mpo_derivatives.jl
+++ b/src/algorithms/derivatives/mpo_derivatives.jl
@@ -27,10 +27,10 @@ const MPO_AC2_Hamiltonian{L, O₁, O₂, R} = MPODerivativeOperator{L, Tuple{O
 MPO_AC2_Hamiltonian(GL, O1, O2, GR) = MPODerivativeOperator(GL, (O1, O2), GR)
 
 const MPO_Contracted_AC_Hamiltonian{L, R} = MPOContractedDerivativeOperator{L, R, 1}
-MPO_Contracted_AC_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L,R,1}(GL,  GR)
+MPO_Contracted_AC_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L, R, 1}(GL, GR)
 
 const MPO_Contracted_AC2_Hamiltonian{L, R} = MPOContractedDerivativeOperator{L, R, 2}
-MPO_Contracted_AC2_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L,R,2}(GL, GR)
+MPO_Contracted_AC2_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L, R, 2}(GL, GR)
 
 # Constructors
 # ------------
@@ -169,4 +169,4 @@ function (h::MPO_Contracted_AC2_Hamiltonian)(
     )
     @plansor y[-1 -2; -3 -4] ≔ h.leftenv[-1 -2 5; 1 2] * x[1 2; 3 4] * h.rightenv[3 4 5; -3 -4]
     return y isa AbstractBlockTensorMap ? only(y) : y
-end
\ No newline at end of file
+end

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks for the quick work! Do you already have some idea of the performance difference for your specific case?

I'll try and come up with some reasonable set of cases to actually benchmark this on, I'd like to experiment with how much of a difference it actually makes even for the more modest MPO sizes too.

Comment thread src/algorithms/derivatives/hamiltonian_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/hamiltonian_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/hamiltonian_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/hamiltonian_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/hamiltonian_derivatives.jl Outdated
@AFeuerpfeil

Copy link
Copy Markdown
Contributor Author

Thanks for your comments.
Making the contractions planar instead of choosing the optimal contraction and permutation order leads to an increase in computation time and total allocations of around 30-50%.
Let's discuss tomorrow how to go about this.

@codecov

codecov Bot commented Oct 7, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.91549% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/algorithms/derivatives/mpo_derivatives.jl 72.97% 10 Missing ⚠️
Files with missing lines Coverage Δ
.../algorithms/derivatives/hamiltonian_derivatives.jl 95.09% <100.00%> (+2.32%) ⬆️
src/algorithms/statmech/idmrg.jl 97.72% <100.00%> (-0.76%) ⬇️
src/algorithms/derivatives/mpo_derivatives.jl 62.79% <72.97%> (-4.56%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AFeuerpfeil

Copy link
Copy Markdown
Contributor Author

I moved my changes to the mpo_derivatives by creating a new struct MPOContractedDerivativeOperator and overloading the general methods for MPS-MPO-MPS contractions.
I use this interface in the hamiltonian_derivatives.jl.
There are 2 issues with this commit:

  1. In the functions domain/codomain, the operators h.O are used. I am not completely sure how to fix that.
  2. When using the new structs in the hamiltonian_derivatives, it slightly increases allocations, as I have not yet implemented an in-place version of applying the contracted MPO derivatives. Which interface should I use for that?

Comment thread src/algorithms/derivatives/mpo_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/mpo_derivatives.jl Outdated
Comment thread src/algorithms/derivatives/mpo_derivatives.jl Outdated
@lkdvos

lkdvos commented Oct 7, 2025

Copy link
Copy Markdown
Member

I know what's causing the test failures, I'll have a look later today to see if I can resolve this in a better way.

@AFeuerpfeil

Copy link
Copy Markdown
Contributor Author

(@lkdvos: Please ignore the latest commit, I forgot to create a new branch)

This reverts commit 6950267.
@lkdvos lkdvos closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants